package view.GUI.actions;

import controller.Constants;
import controller.commands.BasicCommand;
import controller.commands.MacroCommand;
import controller.commands.SetVisibleCommand;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Set;
import javax.swing.AbstractAction;
import model.graphic.GraphicModel;
import model.graphic.objects.Graphical;
import model.graphic.objects.RectangleGraphical;
import view.GUI.graphic.GraphicView;

/**
 *
 * @author Ben
 */
public class HideAllPortsAction extends AbstractAction {

    private GraphicView gview;
    private GraphicModel gmodel;
    private Graphical g;

    public HideAllPortsAction(GraphicView gview,GraphicModel gmodel, Graphical g) {
        this.gview = gview;
        this.gmodel = gmodel;
        this.g=g;
    }

    public void actionPerformed(ActionEvent e) {
        System.out.println("HideAllPortsAction actionPerformed");
        ArrayList<BasicCommand> commands = new ArrayList<BasicCommand>();
        Set<Graphical> ports = gmodel.getAttachedObjects(((RectangleGraphical)g), Constants.getInportsString());
        ports.addAll(gmodel.getAttachedObjects(((RectangleGraphical)g), Constants.getOutportsString()));
        for(Graphical port: ports){
            commands.add(new SetVisibleCommand(port,false));
        }
        gview.notifyObservers(new MacroCommand(commands));
        ((RectangleGraphical)g).getResizer().setVisible(true);
    }
}
